package com.relax.mybatis.encrypt.util;

import com.relax.mybatis.constant.Algorithm;
import com.relax.mybatis.encrypt.algorithm.AES;
import com.relax.mybatis.encrypt.algorithm.HybridAlgorithm;
import com.relax.mybatis.encrypt.algorithm.MD5;
import com.relax.mybatis.encrypt.algorithm.SM2;
import com.relax.mybatis.encrypt.algorithm.SM3;
import com.relax.mybatis.encrypt.algorithm.SM4;
import com.relax.mybatis.constant.EncryptConstants;

/**
 * Test
 *
 * @author hebin
 * @date 2024/6/19
 * @since
 */
public class Test {

    public static void main(String[] args) throws Exception {
        String data = "春花秋月何时了？往事知多少。";
        String password = EncryptConstants.DEFAULT_PASSWORD;
        String publicKey =
                "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEeewAxQEdJ/jDoaXTInthyrNi5kHMSQWyz3brP/QgUirYhWOikRY3GYWQkRqSzH+8InA2Vj2FdgwgeZ6WGae/2g==";
        String privateKey =
                "MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgP6OdzqADfQfcbjRMRtbjhc3V7F+cYTVPsFLpPtYFEeigCgYIKoEcz1UBgi2hRANCAAR57ADFAR0n+MOhpdMie2HKs2LmQcxJBbLPdus/9CBSKtiFY6KRFjcZhZCRGpLMf7wicDZWPYV2DCB5npYZp7/a";
        System.out.println("明文:" + data);
        System.out.println("密码:" + password);
        System.out.println("公钥:" + publicKey);
        System.out.println("私钥:" + privateKey);
        System.out.println("MD5_32:" + MD5.encodeToHex(data));
        System.out.println("MD5_16:" + MD5.encode16ToHex(data));
        System.out.println("AES加密:" + AES.encryptToBase64(data, password));
        System.out.println("AES解密:" + AES.decryptFromBase64(AES.encryptToBase64(data, password), password));
        System.out.println("SM2加密:" + SM2.encryptToBase64(data, publicKey));
        System.out.println("SM2解密:" + SM2.decryptFromBase64(SM2.encryptToBase64(data, publicKey), privateKey));
        System.out.println("SM3加密:" + SM3.encryptToHex(data));
        System.out.println("SM4加密:" + SM4.encryptToBase64(data, password));
        System.out.println("SM4解密:" + SM4.decryptFromBase64(SM4.encryptToBase64(data, password), password));
        String encrypt = HybridAlgorithm.encrypt(Algorithm.PBEWithMD5AndDES, true, data, password);
        System.out.println("混合加密:" + encrypt);
        String decrypt = HybridAlgorithm.encrypt(Algorithm.PBEWithMD5AndDES, false, encrypt, password);
        System.out.println("混合解密：" + decrypt);
    }

}
